<!DOCTYPE html>
<title>Test that "error" event is fired from "source" element when it can not be used.</title>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<video>
    <source id="missing-src" type="video/blahblah"></source>
    <source id="bogus-type" src="content/test.ogv" type="video/blahblah"></source>
    <source id="empty-src" src="" type="video/ogg"></source>
    <source id="no-extension-no-type" src="nonexistent"></source>
</video>
<script>
async_test(function(t) {
    var errorCount = 0;
    document.addEventListener("error", function(event) {
        assert_true(event.target instanceof HTMLSourceElement);
        assert_equals(document.querySelector("video").error, null);
        assert_less_than(errorCount, 4);

        if (++errorCount == 4)
            setTimeout(t.step_func_done(), 200);
    }, true);
});
</script>